<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>javascript 阶段</title>
    <style>
        button {
            padding: 10px 30px;
        }
    </style>
</head>
<body>

    <button class="btn">点击按钮</button>


    <script>
        // 获取按钮标签
        var btn = document.querySelector(".btn");

        var count = 0;
        // 定义函数（代码块）
        var foo = function(){
            count ++;
            console.log("test:"+count);

            if(count >= 5){
                // 当count大于等于5时，就移除事件监听
                btn.removeEventListener("click",foo);
            }
        }

        // 事件监听 
        // btn.addEventListener("click" , function(){})
        btn.addEventListener("click" , foo);

        // 移除事件监听
        // btn.removeEventListener("click",foo);
       

    </script>
</body>
</html>